package com.hntest.service.impl;
import com.hntest.dao.LoginDao;
import com.hntest.entity.LoginInfo;
import com.hntest.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("loginService")
public class LoginServiceImpl implements LoginService {

    @Autowired
    private LoginDao loginDao;
    public void  setLoginDao(LoginDao loginDao){
        this.loginDao=loginDao;
    }

    @Override
    @Transactional(readOnly = true)
    public LoginInfo login(LoginInfo logininfo) {
        System.out.println("调用登录业务方法");
        return loginDao.login(logininfo);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.READ_COMMITTED,timeout=36000,rollbackFor=Exception.class)
    public boolean reregist(LoginInfo loginInfo) {
        System.out.println("调用注册业务方法");
        int n=loginDao.rereg(loginInfo);
        if(n>0) {
            return true;
        }else {
            return false;
        }
    }

    @Override
    @Transactional(readOnly = true)
    public LoginInfo loginAdmin(LoginInfo logininfo) {
        System.out.println("调用后台登录业务方法");
        LoginInfo l = loginDao.loginAdmin(logininfo);
        //System.out.println("------>>>"+l);
        return loginDao.loginAdmin(logininfo);
    }

    @Override
    public boolean insel(LoginInfo loginInfo) {
        List<LoginInfo> list=loginDao.selectLogin(loginInfo.getUsername());
        int id=list.get(0).getLid();
        int n=loginDao.inselect(id);
        if(n>0) {
            return true;
        }else {
            return false;
        }
    }

    @Override
    public List<LoginInfo> selectLogin(String username) {
        return loginDao.selectLogin(username);
    }
}
